
var zone;

var dbase

function init()
{
	//初始化扩展的时候，将当前的zone的引用保存起来
	zone = _server.getCurrentZone();
	
	dbase = _server.getDatabaseManager();
	
}

function destroy()
{
	delete dbase
}

function handleRequest(cmd, params, user, fromRoom)
{
	// 获取消息发送在房间里的 所有user
	users=zone.getRoom(fromRoom).getAllUsers();
	//根据不同的指令 进行不同的操作
	switch(cmd){
		case "move_cmd":
			handleMove(cmd, params, user, fromRoom);//处理人物移动信息
			break;
		case "switch_room_cmd":
			switchRoom(cmd, params, user, fromRoom);
			break;
	}
}

function handleInternalEvent(evt)
{
	
}

function handleMove(cmd,prms,usr,fromRoom) {
	
	/*var px=prms[0];//user发送的x坐标
	var py=prms[1];//user发送的y坐标
	var cmd="move";//指令代号
	var name=usr.getName();*/
	
	var response = {}
	response._cmd=cmd
	response.px=prms[0]	//x
	response.py=prms[1]	//y
	response.name=usr.getName()
	//以字符串的格式 发送移动信息 给房间里的其他user
	//_server.sendResponse([cmd,px,py,name], -1, null, users,"str");
	_server.sendResponse(response, -1, null, users);
	
	var sql = "update pvs.users set ";
	sql +=  "lastX=" +_server.escapeQuotes(prms[0]);
	sql += ",lastY= "+_server.escapeQuotes(prms[1]);
	sql += " where userNumber="+_server.escapeQuotes(prms[2]);
	//trace(sql);
	dbase.executeCommand(sql);
}

function switchRoom(cmd, params, user, fromRoom){
	var sql = "update pvs.users set ";
	sql +=  "lastMapId=" +_server.escapeQuotes(params.mapId);
	//trace(sql);
	dbase.executeCommand(sql);
}








